package com.zggk.lzz.xxyd;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zggk.lzz.R;
import com.zggk.lzz.adapter.LGRecycleViewAdapter;
import com.zggk.lzz.adapter.LGViewHolder;
import com.zggk.lzz.mvp.MVPBaseActivity;
import com.zggk.lzz.pdf.PdfActivity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class XxydActivity extends MVPBaseActivity<XxydContract.View, XxydPresenter> implements XxydContract.View {

    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.view_lay)
    View viewLay;
    @Bind(R.id.recycle_view)
    RecyclerView recycleView;
    @Bind(R.id.wt_te)
    LinearLayout wtTe;
    @Bind(R.id.disease_new_parent_layout)
    RelativeLayout diseaseNewParentLayout;
    private List<XxydBean.DataBean> ListDatas = new ArrayList<>();
    private LGRecycleViewAdapter<XxydBean.DataBean> adapter;

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_xxyd;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        initView();
        initData();
        setTitleText("制度法规");
    }

    private void initData() {
        mPresenter.getData(XxydActivity.this);
    }

    private void initView() {
        recycleView.setHasFixedSize(true);
        recycleView.setNestedScrollingEnabled(false);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(manager);
        adapter = new LGRecycleViewAdapter<XxydBean.DataBean>(ListDatas) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_sjcx;
            }

            @Override
            public void convert(LGViewHolder holder, XxydBean.DataBean zCDBean, int position) {
                holder.setText(R.id.name_te, zCDBean.getFileName());
                holder.setText(R.id.scmc_te, getDateTimeFromMillisecond(zCDBean.getCreateTime()+""));
                TextView bhlx_te = (TextView) holder.getView(R.id.bhlx_te);
                bhlx_te.setVisibility(View.GONE);
                TextView sj_te = (TextView) holder.getView(R.id.sj_te);
                sj_te.setVisibility(View.GONE);
                ImageView ic_img = (ImageView) holder.getView(R.id.ic_img);
                Glide.with(XxydActivity.this).load(R.drawable.pdf_img).into(ic_img);
            }
        };
        recycleView.setAdapter(adapter);
        adapter.setOnItemClickListener(R.id.re_lay, new LGRecycleViewAdapter.ItemClickListener() {
            @Override
            public void onItemClicked(View view, int position) {
                Intent intent = new Intent(XxydActivity.this, PdfActivity.class);
                intent.putExtra("id", ListDatas.get(position).getId());
                startActivity(intent);
            }
        });
    }
    public static String getDateTimeFromMillisecond(String millisecond){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZZ");
        Date date = new Date();
        try {
            date = sdf.parse(millisecond);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String sDate=sdf2.format(date);
        return sDate;
    }
    @Override
    public void getDatas(List<XxydBean.DataBean> dataBeans) {
        ListDatas.addAll(dataBeans);
        adapter.notifyDataSetChanged();
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
